package com.member.shop.service.impl;

import java.util.Arrays;
import java.util.List;

import com.member.common.utils.DateUtils;

import javax.annotation.Resource;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.member.shop.domain.SysBizUser;
import com.member.shop.mapper.SysBizUserMapper;
import com.member.shop.vo.SysBizShopCertificationVo;
import org.springframework.stereotype.Service;
import com.member.shop.mapper.SysBizShopCertificationMapper;
import com.member.shop.domain.SysBizShopCertification;
import com.member.shop.service.ISysBizShopCertificationService;

/**
 * 店铺认证Service业务层处理
 *
 * @author lixinchen
 * @date 2025-01-10
 */
@Service
public class SysBizShopCertificationServiceImpl extends ServiceImpl<SysBizShopCertificationMapper, SysBizShopCertification> implements ISysBizShopCertificationService {
    @Resource
    private SysBizShopCertificationMapper sysBizShopCertificationMapper;

    @Resource
    private SysBizUserMapper sysBizUserMapper;


    /**
     * 查询店铺认证
     *
     * @param id 店铺认证主键
     * @return 店铺认证
     */
    @Override
    public SysBizShopCertification selectSysBizShopCertificationById(Long id) {
        SysBizShopCertification sysBizShopCertification = sysBizShopCertificationMapper.selectById(id);
        if(sysBizShopCertification!=null && sysBizShopCertification.getSalesUserId()!=null){
            SysBizUser sysBizUser = sysBizUserMapper.selectById(sysBizShopCertification.getSalesUserId());
            sysBizShopCertification.setSalesUserPhone(sysBizUser.getUserPhone());
        }

        return sysBizShopCertification;
    }

    /**
     * 查询店铺认证列表
     *
     * @param queryWrapper 店铺认证
     * @return 店铺认证
     */
    @Override
    public List<SysBizShopCertification> selectSysBizShopCertificationList(LambdaQueryWrapper<SysBizShopCertification> queryWrapper) {
        return sysBizShopCertificationMapper.selectList(queryWrapper);
    }

    @Override
    public List<SysBizShopCertification> selectSysBizShopCertificationList(SysBizShopCertification sysBizShopCertification) {
        return sysBizShopCertificationMapper.selectSysBizShopCertificationList(sysBizShopCertification);
    }

    /**
     * 新增店铺认证
     *
     * @param sysBizShopCertification 店铺认证
     * @return 结果
     */
    @Override
    public int insertSysBizShopCertification(SysBizShopCertification sysBizShopCertification) {
        sysBizShopCertification.setCreateTime(DateUtils.getNowDate());
        return sysBizShopCertificationMapper.insert(sysBizShopCertification);
    }

    /**
     * 修改店铺认证
     *
     * @param sysBizShopCertification 店铺认证
     * @return 结果
     */
    @Override
    public int updateSysBizShopCertification(SysBizShopCertification sysBizShopCertification) {
        sysBizShopCertification.setUpdateTime(DateUtils.getNowDate());
        return sysBizShopCertificationMapper.updateById(sysBizShopCertification);
    }

    /**
     * 批量删除店铺认证
     *
     * @param ids 需要删除的店铺认证主键
     * @return 结果
     */
    @Override
    public int deleteSysBizShopCertificationByIds(Long[] ids) {
        return sysBizShopCertificationMapper.deleteBatchIds(Arrays.asList(ids));
    }

    /**
     * 删除店铺认证信息
     *
     * @param id 店铺认证主键
     * @return 结果
     */
    @Override
    public int deleteSysBizShopCertificationById(Long id) {
        SysBizShopCertification sysBizShopCertification = new SysBizShopCertification();
        sysBizShopCertification.setId(id);
        sysBizShopCertification.setDeleted(1);
        sysBizShopCertification.setUpdateTime(DateUtils.getNowDate());
        return sysBizShopCertificationMapper.updateById(sysBizShopCertification);
    }

    @Override
    public List<SysBizShopCertificationVo> selectSysBizShopCertificationExport() {
        return sysBizShopCertificationMapper.selectSysBizShopCertificationExport();
    }
}
